package com.mall.user.services;

import com.mall.user.dal.entitys.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class EmailServiceImpl {
    @Autowired
    JavaMailSender javaMailSender;

    @Async
    void sendEmail(Member member) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("localhost:8080/user/verify?uid=")
                .append(member.getPassword())
                .append("&username=")
                .append(member.getUsername());
        String emailTxt = stringBuffer.toString();
        simpleMailMessage.setText(emailTxt);
        simpleMailMessage.setTo(member.getEmail());
        simpleMailMessage.setSubject("用户验证");
        simpleMailMessage.setFrom("13127833397@163.com");
        javaMailSender.send(simpleMailMessage);
    }
}
